﻿using DE_MVC_WyFy.Areas.Administrator.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DE_MVC_WyFy.Models
{
	public class ProductTypeController : Controller
	{
		//
		// GET: /ProducType/

		public ActionResult Index()
		{
			return Redirect("Home");
		}
	
		public ActionResult Detail(int id)
		{
			ProductType db = ProductType.Objects.GetById(id);
			List<Product> lsProd = new List<Product>();
			List<ProductType> nav = ProductType.Objects.Find(c => c.Parent == id).ToList();
			List<Int32> lsChild = db.IdChild;
			if (lsChild != null)
			{

				foreach (var item in lsChild)
				{
					List<Product> temp = Product.Objects.Find(c => c.ProductTypeID == item).ToList();
					lsProd.AddRange(temp);
				}
			}

			lsProd.AddRange(Product.Objects.Find(c => c.ProductTypeID == id).ToList());
			ViewBag.Nav = nav;
			//ViewData["Nav"] = nav;
			ViewBag.Product = lsProd;
			return View(db);
		}
	}
}
